﻿
Imports System.Runtime.CompilerServices

Public Module _network
    <Extension()> Public Function parse_tcp_parameters(ByVal v As var,
                                                       Optional ByRef is_outgoing As String = Nothing,
                                                       Optional ByRef host As String = Nothing,
                                                       Optional ByRef port As String = Nothing,
                                                       Optional ByRef target As String = Nothing,
                                                       Optional ByRef token As String = Nothing,
                                                       Optional ByRef max_connecting As String = Nothing,
                                                       Optional ByRef max_connected As String = Nothing,
                                                       Optional ByRef no_delay As String = Nothing,
                                                       Optional ByRef connecting_timeout_ms As String = Nothing,
                                                       Optional ByRef response_timeout_ms As String = Nothing,
                                                       Optional ByRef send_rate_sec As String = Nothing,
                                                       Optional ByRef receive_rate_sec As String = Nothing,
                                                       Optional ByRef max_lifetime_ms As String = Nothing,
                                                       Optional ByRef ipv4 As String = Nothing,
                                                       Optional ByRef enable_keepalive As String = Nothing,
                                                       Optional ByRef first_keepalive_ms As String = Nothing,
                                                       Optional ByRef keepalive_interval_ms As String = Nothing,
                                                       Optional ByRef zipper As String = Nothing,
                                                       Optional ByRef encryptor As String = Nothing) _
                                                      As Boolean
        Const p_is_outgoing As String = "is-outgoing"
        Const p_host As String = "host"
        Const p_port As String = "port"
        Const p_target As String = "target"
        Const p_token As String = "token"
        Const p_max_connecting As String = "max-connecting"
        Const p_max_connected As String = "max-connected"
        Const p_no_delay As String = "no-delay"
        Const p_connecting_timeout_ms As String = "connecting-timeout-ms"
        Const p_response_timeout_ms As String = "response-timeout-ms"
        Const p_send_rate_sec As String = "send-rate-sec"
        Const p_receive_rate_sec As String = "receive-rate-sec"
        Const p_max_lifetime_ms As String = "max-lifetime-ms"
        Const p_ipv4 As String = "ipv4"
        Const p_enable_keepalive As String = "enable-keepalive"
        Const p_first_keepalive_ms As String = "first-keepalive-ms"
        Const p_keepalive_interval_ms As String = "keepalive-interval-ms"
        Const p_zipper As String = "zipper"
        Const p_encryptor As String = "encryptor"
        If v Is Nothing Then
            Return False
        Else
            v.bind(p_is_outgoing,
                   p_host,
                   p_port,
                   p_target,
                   p_token,
                   p_max_connecting,
                   p_max_connected,
                   p_no_delay,
                   p_connecting_timeout_ms,
                   p_response_timeout_ms,
                   p_send_rate_sec,
                   p_receive_rate_sec,
                   p_max_lifetime_ms,
                   p_ipv4,
                   p_enable_keepalive,
                   p_first_keepalive_ms,
                   p_keepalive_interval_ms,
                   p_zipper,
                   p_encryptor)
            is_outgoing = v(p_is_outgoing)
            host = v(p_host)
            port = v(p_port)
            target = v(p_target)
            token = v(p_token)
            max_connecting = v(p_max_connecting)
            max_connected = v(p_max_connected)
            no_delay = v(p_no_delay)
            connecting_timeout_ms = v(p_connecting_timeout_ms)
            response_timeout_ms = v(p_response_timeout_ms)
            send_rate_sec = v(p_send_rate_sec)
            receive_rate_sec = v(p_receive_rate_sec)
            max_lifetime_ms = v(p_max_lifetime_ms)
            ipv4 = v(p_ipv4)
            enable_keepalive = v(p_enable_keepalive)
            first_keepalive_ms = v(p_first_keepalive_ms)
            keepalive_interval_ms = v(p_keepalive_interval_ms)
            zipper = v(p_zipper)
            encryptor = v(p_encryptor)
            Return True
        End If
    End Function

    <Extension()> Public Function parse_http_parameters(
                                      ByVal v As var,
                                      Optional ByRef host As String = Nothing,
                                      Optional ByRef port As String = Nothing,
                                      Optional ByRef target As String = Nothing,
                                      Optional ByRef max_connection_count As String = Nothing,
                                      Optional ByRef connect_timeout_ms As String = Nothing,
                                      Optional ByRef response_timeout_ms As String = Nothing,
                                      Optional ByRef buff_size As String = Nothing,
                                      Optional ByRef single_copy_timeout_ms As String = Nothing,
                                      Optional ByRef copy_timeout_ms As String = Nothing,
                                      Optional ByRef max_content_length As String = Nothing) As Boolean
        Const p_host As String = "host"
        Const p_port As String = "port"
        Const p_target As String = "target"
        Const p_max_connection_count As String = "max-connection-count"
        Const p_connect_timeout_ms As String = "connect-timeout-ms"
        Const p_response_timeout_ms As String = "response-timeout-ms"
        Const p_buff_size As String = "buff-size"
        Const p_single_copy_timeout_ms As String = "single-copy-timeout-ms"
        Const p_copy_timeout_ms As String = "copy-timeout-ms"
        Const p_max_content_length As String = "max-content-length"
        If v Is Nothing Then
            Return False
        Else
            v.bind(p_host,
                   p_port,
                   p_target,
                   p_max_connection_count,
                   p_connect_timeout_ms,
                   p_response_timeout_ms,
                   p_buff_size,
                   p_single_copy_timeout_ms,
                   p_copy_timeout_ms,
                   p_max_content_length)
            host = v(p_host)
            port = v(p_port)
            target = v(p_target)
            max_connection_count = v(p_max_connection_count)
            connect_timeout_ms = v(p_connect_timeout_ms)
            response_timeout_ms = v(p_response_timeout_ms)
            buff_size = v(p_buff_size)
            single_copy_timeout_ms = v(p_single_copy_timeout_ms)
            copy_timeout_ms = v(p_copy_timeout_ms)
            max_content_length = v(p_max_content_length)
            Return True
        End If
    End Function
End Module
